import { Enum } from 'cc';
export type PanelConfigInfo = {
    assetbundle: string, assetPath: string,
    tier?: string,
    destroy?: boolean,
    scene?: boolean // 随场景带入
    name?: string // 随场景带入则需要填写
}

export enum PanelKey {
    EMPTY
}
Enum(PanelKey);

export const UIConfigList = [];

export const UIConfig = new Map<string, Map<PanelKey, PanelConfigInfo>>([['_', new Map<PanelKey, PanelConfigInfo>(UIConfigList as any)]]);

export function makePrefabStrToPanelKeyMap(configList: typeof UIConfigList, map: Map<string, PanelKey>) {
    for (let i = 0; i < configList.length; i++) {
        let item = configList[i];
        let className = (item[1] as any).className as string;
        if (className != null) {
            map.set(className, item[0] as PanelKey);
        } else { // className为空,就根据prefab的名字推断,一般情况应该是一样的
            let assetPath = (item[1] as any).assetPath as string;
            let prefabName = assetPath.substring(assetPath.lastIndexOf('/') + 1);
            map.set(prefabName, item[0] as PanelKey);
        }
    }
    return map;
}

export const PrefabNameToPanelKeyMap = new Map<string, PanelKey>();
makePrefabStrToPanelKeyMap(UIConfigList, PrefabNameToPanelKeyMap);

globalThis.UIConfig = UIConfig;
globalThis.PrefabNameToPanelKeyMap = PrefabNameToPanelKeyMap;